import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class Test04 {
    public static void main(String[] args) {
        /*
	3.定义测试类TestStudentTool，在main方法中首先创建长度为5的Student数组并初始化数据,再创建StudentsTool类的对象,并调用以上方法
         */
        StudentsTool a=new StudentsTool();
        List<Student1> list=new ArrayList<Student1>();
        list.add(new Student1("刘齐",21,100));
        list.add(new Student1("王作楷",22,90));
        Student1 arr[]=new Student1[list.size()];
        for(int i=0;i<list.size();i++){
            arr[i]= list.get(i);
        }
        a.listStudents(arr);
        a.getCount(arr);
        a.getAverageScore(arr);
    }
}
class Student1{
    /*
    学生类
			属性：
				姓名name
				年龄age
				成绩score
			行为：
			吃饭eat()
			stuty(String content)(content:表示学习的内容)
     */
    private String name;
    private Integer age;
    private Integer score;
    public void eat(){

    }
    public void stuty(String content){

    }

    public Student1() {
    }

    public Student1(String name, Integer age, Integer score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Integer getScore() {
        return score;
    }

    public void setScore(Integer score) {
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student1{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student1 student1 = (Student1) o;
        return Objects.equals(name, student1.name) && Objects.equals(age, student1.age) && Objects.equals(score, student1.score);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age, score);
    }
}
class StudentsTool extends Student1{
    /*
		public void listStudents(Student[] arr):遍历打印学生信息
     */
    public void listStudents(Student1[] arr){
        for(int i=0;i<arr.length;i++){
            System.out.println(arr[i].toString());
        }
    }
    /*
    public int getMaxScore(Student[] arr):获取学生成绩的最高分
     */
    public int getMaxScore(Student1[] arr){
        Integer max=arr[0].getScore();
        for(int i=0;i<arr.length;i++){
            if(max<arr[i].getScore()){
                max=arr[i].getScore();
            }
        }
        return max;
    }
    /*
    public Student getMaxStudent(Student[] arr):获取成绩最高的学员
     */
    public Student1 getMaxStudent(Student1[] arr){
        Integer max=arr[0].getScore();
        for(int i=0;i<arr.length;i++){
            if(max<arr[i].getScore()){
                max=arr[i].getScore();
            }
        }
        Student1 maxStudent=null;
        for(int i=0;i<arr.length;i++){
            if(max.equals(arr[i].getName())){
                maxStudent=arr[i];
            }
        }
        return maxStudent;
    }
    /*
    public int getAverageScore(Student[] arr):获取学生成绩的平均值
     */
    public int getAverageScore(Student1[] arr){
        Integer allScore=0;
        for(int i=0;i<arr.length;i++){
            allScore+=arr[i].getScore();
        }
        int avg=allScore/arr.length;
        return avg;
    }
    /*
    public int getCount(Student[] arr):获取不及格的学员数量
     */
    public int getCount(Student1[] arr){
        int num=0;
        for(int i=0;i<arr.length;i++){
            if(60>arr[i].getScore()){
                num++;
            }
        }
        return num;
    }
}